program XML;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows,
  ActiveX,
  uDZStr,
  uDZXML,
  XMLIntf,
  XMLDoc;

const
  XMLText: PWideChar = '<root a="1" /><root>abcd<level21></level21><level2>abcd<level3></level3>' +
    '<level3 name2 = "caonima" name = "fuck"></level3><level3_2></level3_2></level2>abcd</root><root1></root1>';
  XMLPath = '/root[2]/[2]/level3[2]';
  AttrName: PWideChar = 'name2';
var
  Info: TXMLNodeInfoW;
  AttrVPtr, AttrVEnd: PWideChar;
  doc: IXMLDocument;
begin
  try
    CoInitialize(nil);
    doc := NewXMLDocument;
    doc.Encoding := 'utf-16';
    doc.AddChild('root');
    doc.DocumentElement.AddChild('root').Text := '1';
    doc.SaveToFile('D:\123.xml');
    CoUninitialize;
    Exit;
    try
      if XMLGetNodeInfoW(XMLText, Length(XMLText), XMLPath, Length(XMLPath), Info) then
      begin
        Writeln(Info.NameLT^);
        Writeln(Info.Name);
        Writeln(Info.NameGT^);
        if XMLGetAttributeW(Info.NameEnd + 1, PWideChar(XMLText) + Length(XMLText),
          PWideChar(AttrName), PWideChar(AttrName) + Length(AttrName),
            AttrVPtr, AttrVEnd) then
        begin
          Writeln(WideStrFromBuf(AttrVPtr, 2 * (AttrVEnd - AttrVPtr)));
        end;
      end;
    except
      on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
    end;
  finally
    Readln;
  end;
end.
